/**
 * @author 艾尼亚尔
 * @date 2025/8/8
 * @description 图标工具 - 集成多个图标库并统一导出
 */
import { markRaw } from 'vue'
import type { Component } from 'vue'
import * as tabler from '@vicons/tabler'
import * as carbon from '@vicons/carbon'
import * as antd from '@vicons/antd'
import * as fluent from '@vicons/fluent'
import * as material from '@vicons/material'
import * as fa from '@vicons/fa'
import * as ionicons5 from '@vicons/ionicons5'
import * as ionicons4 from '@vicons/ionicons4'

// 定义图标集合类型
type IconSet = Record<string, Component>

/**
 * 为图标添加前缀并标记为非响应式
 * @param lib 图标库对象
 * @param prefix 前缀字符串
 * @returns 添加前缀后的图标集合
 */
function addPrefixToIcons(lib: Record<string, Component>, prefix: string): IconSet {
  return Object.entries(lib).reduce((acc, [key, component]) => {
    // 使用 markRaw 确保组件不会被转换为响应式对象
    acc[`${prefix}-${key}`] = markRaw(component)
    return acc
  }, {} as IconSet)
}

// 导出整合后的图标集合，整个对象也标记为非响应式
export default markRaw({
  ...addPrefixToIcons(tabler, 'tabler'),
  ...addPrefixToIcons(carbon, 'carbon'),
  ...addPrefixToIcons(antd, 'ant'),
  ...addPrefixToIcons(fluent, 'fluent'),
  ...addPrefixToIcons(material, 'material'),
  ...addPrefixToIcons(fa, 'fa'),
  ...addPrefixToIcons(ionicons5, 'ion5'),
  ...addPrefixToIcons(ionicons4, 'ion4'),
}) as IconSet
